import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('../views/HomeView.vue'),
    meta:{//原数据
      title:'首页'
    }
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),
    meta:{//描述数据
      title:'首页'
    }
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue'),
    meta:{//描述数据
      title:'关于我们'
    }
  },

  {
    path: '/release',
    name: 'release',
    component: () => import('../views/ReleaseView.vue'),
    meta:{//描述数据
      title:'发布帖子'
    }
  },
  {
    path: '/school',
    name: 'school',
    redirect:"share1",
    component: () => import('../views/SchoolView.vue'),
    children: [
      {
        path: '/share1',
        name: 'share1',
        component: () => import('../views/Share/AllShareView.vue'),
      
      },
      {
        path: '/share2',
        name: 'share2',
        component: () => import('../views/Share/guangtang.vue'),
      
      },
      {
        path: '/share3',
        name: 'share3',
        component: () => import('../views/Share/shewang.vue'),
      
      },
    ],
    meta:{//描述数据
      title:'校园分享'
    },

  },
  
  {
    path: '/details',
    name: 'details',
    component: () => import('../views/DetailsPageView.vue'),
    meta:{//描述数据
      title:'详情页'
    }
  },

  
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue'),
    meta:{//描述数据
      title:'登录'
    }
  },

    //个人中心跳转
  {
    name: "PersonalCenter",
    path: '/PersonalCenter',
    redirect:"personal",
    component: () => import('../components/PersonalCenter.vue'),
    children: [
      {
        path: '/personal',
        name: 'personal',
        component: () => import('../views/person/personal.vue')
      },
      {
        path: '/favorites',
        name: 'favorites',
        component: () => import('../views/person/favorites.vue')
      },
      {
        path: '/concerns',
        name: 'concerns',
        component: () => import('../views/person/concerns.vue')
      },
    ],
    meta:{//描述数据
      title:'个人中心'
    }
  }



]

const router = new VueRouter({
  mode: 'history',

  routes
})
//定义动态标题
router.beforeEach((to,from,next)=>{
  console.log(to);
  //从from(来自)跳转到to
  document.title=to.matched[0].meta.title;
  //下一步
  next()
})

export default router
